package com.aistar.hotel.controller;


import com.aistar.common.vo.PageList;
import com.aistar.common.vo.Result;
import com.aistar.hotel.entity.Hotel;
import com.aistar.hotel.service.HotelMapperService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Created by wubin on 2019/6/25.
 */
@RestController
public class HotelController {
    @Autowired
    private HotelMapperService hotelMapperService;
    @GetMapping("/hotel")
    public Result findAll(Hotel hotel) {

        List<Hotel> list = hotelMapperService.findAll("");
        Result result = new Result(true, 20000, "查询成功", list);
        return result;
    }

        @GetMapping("/hotel/{hotelName}")
        public Result find(Hotel hotel){
//            System.out.println(hotel);
            List<Hotel> list =hotelMapperService.findAll(hotel.getHotelName());
            System.out.println(list);
            Result result = new Result(true,20000,"查询成功",list);
            return result;

    }
    @GetMapping("/hotelpage/{pageNow}")
    public Result page(PageList pageList){
//        System.out.println(request.getParameter("PageNow"));
        PageInfo<Hotel> pageInfo = hotelMapperService.getPageInfo("",pageList.getPageNow(),4);
        Result result = new Result(true,20000,"分页成功",pageInfo);
        return result;

    }

    @GetMapping("/hotels/{hotelId}")
    public Result hotelroom(Hotel hotel){
        Hotel hotel1 =hotelMapperService.findById(hotel.getHotelId());
        System.out.println(hotel1);
        Result result = new Result(true,20000,"查询单个对象成功",hotel1);
        return result;

    }


       @GetMapping("/hotel/{hotelType}/{hotelFacilities}/{hotelStar}")
      public Result search(@RequestParam(value = "hotelType",defaultValue ="酒店") String hotelType,@RequestParam(value = "hotelFacilities",defaultValue ="空调") String hotelFacilities,@RequestParam(value = "hotelStar",defaultValue ="5星级") String hotelStar){

        Hotel hotel = new Hotel();
        hotel.setHotelType(hotelType);
        hotel.setHotelFacilities(hotelFacilities);
        hotel.setHotelStar(hotelStar);
        System.out.println(hotel);
        List<Hotel> hotels = hotelMapperService.findByany(hotel);
//        map.put("hotel",hotels);

        Result result = new Result(true,20000,"查询成功",hotels);

        return result;
    }







}
